package com.pagepub.core.utils;

import java.io.Serializable;
import java.text.CollationKey;
import java.text.Collator;

public class CollatorComparator extends Collator implements Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	//private Collator collator = Collator.getInstance();

	private int sort = 1;

	@Override
	public int compare(String arg0, String arg1) {
		// 如果有空值，直接返回0
		if (arg0 == null || arg1 == null)
			return 0;

		//CollationKey key1 = collator.getCollationKey(String.valueOf(arg0));
		//CollationKey key2 = collator.getCollationKey(String.valueOf(arg1));String.valueOf(arg1).toString()
//		String key1Str=arg0;
//		String key2Str=arg1;
		String endorder1=arg0.substring(arg0.lastIndexOf("||")+1);
		String endorder2=arg1.substring(arg1.lastIndexOf("||")+1);
		return sort * endorder1.compareTo(endorder2);//int compare(T o1,T o2)：随第一个参数小于、等于或大于第二个参数而分别返回负整数、零或正整数。 
	}

	/**
	 * 设定排序的方向
	 * 
	 * @param i
	 *            排序方向（正数：正序；负数：倒序）
	 */
	public void setSort(int i) {
		if (i > 0) {
			sort = 1;
		} else if (i < 0) {
			sort = -1;
		}
	}

	@Override
	public CollationKey getCollationKey(String arg0) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public int hashCode() {
		// TODO Auto-generated method stub
		return 0;
	}

}
